package cn.psvmc.cxzapi.controller.customer;

import cn.psvmc.cxzapi.model.common.PageEntity;
import cn.psvmc.cxzapi.model.customer.TCustomerGoodsRecord;
import cn.psvmc.cxzapi.response.*;
import cn.psvmc.cxzapi.service.customer.TCustomerGoodsRecordService;
import cn.psvmc.cxzapi.util.PageUtil;
import cn.psvmc.cxzapi.util.ToolUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 浏览记录
 *
 * @Author auto
 * @Date 2024-08-27
 */
@RestController
@RequestMapping("/mpapi/customer_record")
public class TCustomerGoodsRecordController {

    @Resource
    private TCustomerGoodsRecordService tCustomerGoodsRecordService;

    /**
     * @Description 添加记录
     * @Date 2024/8/27 22:05
     * @Author YWX
     * @Param [tCustomerGoodsRecord]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/add")
    public Result add(@RequestBody TCustomerGoodsRecord tCustomerGoodsRecord) {
        ToolUtils.validation(new Object[]{tCustomerGoodsRecord.getGoodsId(), "商品id", 1});
        tCustomerGoodsRecordService.add(tCustomerGoodsRecord);
        return ResultGenerator.genSuccessResult("保存成功！");
    }

    /**
     * @Description 记录列表
     * @Date 2024/8/27 21:57
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.PageResult2
     **/
    @PostMapping("/list")
    public PageResult2 list(@RequestBody PageEntity entity) {
        Page<TCustomerGoodsRecord> queryPage = new Page<>(entity.getPage(), entity.getSize());
        return PageUtil.getPageResult2(tCustomerGoodsRecordService.list(queryPage));
    }
}
